//app.js
App({
  d: {
   //hostUrl: 'https://admin.sclg.top/api',
    hostUrl: 'https://admin.sclg.top',
    hostImg: 'https://admin.sclg.top/static/app',
    hostVideo: 'https://admin.sclg.top/',
    ceshiUrl: 'https://admin.sclg.top/admin/index.php',
  },
  onLaunch: function () {
    // 展示本地存储能力
    var logs = wx.getStorageSync('logs') || [];
    logs.unshift(Date.now());
    wx.setStorageSync('logs', logs);
    console.log('login');
    this.login();
  },
  login:function(callback){
    wx.login({
      success: res => {
        wx.request({
          url: this.d.hostUrl + '/api/login',
          data: {
            'code': res.code
          },
          method: 'post', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
          header: {
            'Content-type': 'application/x-www-form-urlencoded'
          }, // 设置请求的 header
          success: function (res) {
            console.log(res);
            wx.setStorageSync('openid', res.data.openid);
            wx.setStorageSync('sessionkey', res.data.sessionkey);
            if (res.data.auth_phone == 0) {
              if(callback!=null){
                callback(false);
              }
              wx.reLaunch({
                url: '/pages/onepage/onepage'
              })
            }else {
              if(callback!=null){
                callback(true);
              }

            }
          }
        })
      }
    });
  },
  authinfo:function(){
    wx.request({
      url: this.d.hostUrl + '/api/user/get_myintegral_info',
      data: {
        sessionkey: wx.getStorageSync('sessionkey'),
      },
      method: 'POST',
      header: {
        'Content-type': 'application/x-www-form-urlencoded'
      }, // 设置请求的 header
      success: function (res) {
        console.log(res.data.errmsg);
        var userinfo = res.data.errmsg;
        wx.setStorageSync('userinfo', userinfo);
        // if (userinfo.fans_headimg == null) {
        //   wx.navigateTo({
        //     url: '/pages/userinfo/userinfo', // 希望跳转过去的页面
        //   })
        //   return;
        // }
        // if (userinfo.fans_tel == null) {
        //   wx.navigateTo({
        //     url: '/pages/onepage/onepage', // 希望跳转过去的页面
        //   })
        //   return;
        // }

      }
    })
  },
  // 拨打电话
  gotel: function () {
    wx.makePhoneCall({
      phoneNumber: '400-5453-4534'
    })
  },

  globalData: {
    userInfo: null,
    selectGoods: [],
    myAddr: [{
      link_name: "aa",
      link_phone: "18788888888",
      link_area: ['重庆市', '重庆市', '万州区'],
      link_addr: "红黄路"
    },{
      link_name: "bb",
      link_phone: "18788888888",
      link_area: ['重庆市', '重庆市', '万州区'],
      link_addr: "红黄路"
    }]
  }
})